package com.bishe.demo.modules.hotel.hotelFacilityAndService.controller;

import com.bishe.demo.modules.common.entity.ResultEntity;
import com.bishe.demo.modules.hotel.hotelFacilityAndService.entity.FacilityAndService;
import com.bishe.demo.modules.hotel.hotelFacilityAndService.service.FacilityAndServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class FacilityAndServiceController {
    @Autowired
    private FacilityAndServiceService facilityAndServiceService;

    @PostMapping(value = "/facilityAndService", consumes = "application/json")
    public ResultEntity<FacilityAndService> insertFacilityAndService(@RequestBody FacilityAndService facilityAndService) {
        return facilityAndServiceService.insertFacilityAndService(facilityAndService);
    }

    @GetMapping("/facilityAndService/{hotelId}")
    public FacilityAndService getFacilityAndServiceByHotelId(@PathVariable int hotelId) {
        return facilityAndServiceService.getFacilityAndServiceByHotelId(hotelId);
    }

    @PutMapping(value = "/facilityAndService", consumes = "application/json")
    public ResultEntity<FacilityAndService> updateFacilityAndService(@RequestBody FacilityAndService facilityAndService) {
        facilityAndServiceService.deleteByHotelId(facilityAndService.getUser().getUserId());
        return facilityAndServiceService.insertFacilityAndService(facilityAndService);
    }
}
